[#include "../../../common/html.ftl" /]
[@html]
    [@head title="在线用户列表" css=["fw", "bootstrap-table"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="monitor:online:batchForceLogout"]--]
                    <button class="am-btn am-btn-danger am-radius multiple am-disabled" onclick="javascript:batchForceLogout()">强退</button>
                    [#--[/@shiro.hasPermission]--]
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-online-search" ]
                    <div class="am-form-group">
                        <input type="text" name="ipaddr" class="am-form-field am-input-sm am-radius" placeholder="登录地址">
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="loginName" class="am-form-field am-input-sm am-radius" placeholder="登录名称">
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table"]]
            <script type="text/javascript">
                [#--var forceFlag = "${hasPermission('monitor:online:forceLogout')}";--]
                var forceFlag = "";
                var prefix = ctx + "osfw/system/monitor/online";

                $(function () {
                    var options = {
                        uniqueId: "sessionId",
                        url: prefix + "/list",
                        exportUrl: prefix + "/export",
                        sortName: "lastAccessTime",
                        sortOrder: "desc",
                        showExport: true,
                        escape: true,
                        columns: [{
                            checkbox: true
                        },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'orgId',
                                title: '组织机构名称',
                                formatter: function (value, item, index) {
                                    return $.common.getOrgName(value);
                                }
                            },
                            {
                                field: 'sessionId',
                                title: '会话编号',
                                visible: false
                            },
                            {
                                field: 'loginName',
                                title: '登录名称',
                                sortable: true,
                                formatter: function (value, row, index) {
                                    return $.table.tooltip(value, 10);
                                }
                            },
                            {
                                field: 'deptName',
                                title: '部门名称'
                            },
                            {
                                field: 'ipaddr',
                                title: '主机'
                            },
                            {
                                field: 'loginLocation',
                                title: '登录地点'
                            },
                            {
                                field: 'browser',
                                title: '浏览器'
                            },
                            {
                                field: 'os',
                                title: '操作系统'
                            },
                            {
                                field: 'status',
                                title: '会话状态',
                                align: 'left',
                                formatter: function(value, row, index) {
                                    if (value == 'on_line') {
                                        return '<span class="badge badge-primary">在线</span>';
                                    } else if (value == 'off_line') {
                                        return '<span class="badge badge-danger">离线</span>';
                                    }
                                }
                            },
                            {
                                field: 'startTimestamp',
                                title: '登录时间',
                                sortable: true
                            },
                            {
                                field: 'lastAccessTime',
                                title: '最后访问时间',
                                sortable: true
                            },
                            {
                                title: '操作',
                                cellStyle: operCellStyle,
                                formatter: function(value, row, index) {
                                    var msg = '<a class="am-badge am-badge-transparent am-radius ' + forceFlag + '" href="javascript:void(0)" onclick="forceLogout(\'' + row.sessionId + '\')">强退</a> ';
                                    return msg;
                                }
                            }
                        ]
                    };
                    $.table.init(options);
                });

                // 单条强退
                function forceLogout(sessionId) {
                    $.modal.confirm("确定要强制选中用户下线吗？", function() {
                        var data = { "sessionId": sessionId };
                        $.operate.post(prefix + "/forceLogout", data);
                    })
                }

                // 批量强退
                function batchForceLogout() {
                    var rows = $.table.selectColumns("sessionId");
                    if (rows.length == 0) {
                        $.modal.alertWarning("请选择要强退的用户");
                        return;
                    }
                    $.modal.confirm("确认要强退选中的" + rows.length + "条数据吗?", function() {
                        var url = prefix + "/batchForceLogout";
                        var data = { "ids": rows };
                        $.operate.post(url, data);
                    });
                }

            </script>
        [/@script]
    [/@body]
[/@html]
